#include "tsplcmd.h"
#include "printerclient.h"
#include <QPointer>

TsplCmd::TsplCmd(QObject *parent)
    : QObject{parent}
{

}


TsplCmd* TsplCmd::PageSize(int width, int height){
    data.append(QString("SIZE %1 mm, %2 mm \r\n").arg(width).arg(height).toUtf8());
    return this;
}

TsplCmd* TsplCmd::Gap(int height){
    data.append(QString("GAP %1 mm\r\n").arg(height).toUtf8());
    return this;
}

TsplCmd* TsplCmd::Direction(int vertical, int horizontal){
    data.append(QString("DIRECTION %1, %2\r\n").arg(vertical).arg(horizontal).toUtf8());
    return this;
}

TsplCmd* TsplCmd::Speed(int speed){
    data.append(QString("SPEED %1\r\n").arg(speed).toUtf8());
    return this;
}

TsplCmd* TsplCmd::Density(int density){
    data.append(QString("DENSITY %1\r\n").arg(density).toUtf8());
    return this;
}

TsplCmd* TsplCmd::Reference(int x, int y){
    data.append(QString("REFERENCE %1, %2\r\n").arg(x).arg(y).toUtf8());
    return this;
}

TsplCmd* TsplCmd::Cls(){
    data.append("CLS\r\n");
    return this;
}

TsplCmd* TsplCmd::DrawBitmap(QByteArray &grays, int width, int height, int dpi){
    data.append(QString("BITMAP 0, 0, %1, %2, 0, ").arg(width * dpi / 8).arg(height * dpi).toUtf8());
    data.append(grays);
    data.append("\r\n");
    return this;
}

TsplCmd* TsplCmd::End(){
    data.append("PRINT 1, 1\r\n");
    return this;
}

void TsplCmd::SendToDevice(PrinterClient* client){
    // PrinterClient 如果配置了parnet 会导致打印发送不成功
    // qDebug() << "tsplcma:{" << data << "}";
    client->sendData(data);
    return;
}
